{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
<!--    <div class="layui-btn-container">-->
<!--        <button type="button" lay-event="add" class="layui-btn {:node('Admin/addAdmin')} layui-btn-sm">添加安保人员</button>-->
<!--        <button type="button" lay-event="del" class="layui-btn {:node('Admin/del')} layui-btn-sm layui-btn-danger">-->
<!--            删除安保人员-->
<!--        </button>-->
<!--        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>-->
<!--    </div>-->
</script>
<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('balance')}",
            where:{'id': {$id}},
            // toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
              // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: 'id', field: 'id',width:90},
                {title: '商户编号', field: 'merchant', templet: function (item) {
                        return item.merchant_sn
                    }
                },
                {title: '商户公司', field: 'merchant', templet: function (item) {
                        return item.company
                    }
                },
                {title: '合同号', field: 'merchant', templet: function (item) {
                        return item.code
                    }
                },
                {title: '交易金额变动情况', field: 'edit', templet: function (item) {
                        return item.edit==1?'增加':'减少'
                    }},

                {title: '交易金额（元）', field:'amount',templet: function (item) {
                        return item.amount/100
                    }},
                {title: '类型', field: 'is_top_up',width:90,templet: function (item) {
                        if(item.is_top_up==1){
                            return '充值'
                        }else if(item.is_top_up==2){
                            return '缴费'
                        }else if(item.is_top_up==4){
                            return '线上转入'
                        }else if(item.is_top_up==5){
                            return '退费'
                        }else {
                            return '余额缴费'
                        }
                        // return item.is_top_up==1?'充值':(item.is_top_up==2? '缴费':(item.is_top_up==4? '线上转入':'退押金'))
                    }},
                {title: '交易类型', field: 'is_top_up',width:90,templet: function (item) {
                        if(item.type==1){
                            return '线上充值'
                        }else if(item.type==2){
                            return '转账'
                        }else {
                            return '余额缴费'
                        }
                }},
                // {title: '关联订单号', field: 'order_sn'},
                {title: '交易时间', field: 'create_time',width:160,}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "edit") {
                var urls = "{:url('add')}?id=" + _id;
                lucky.CreateOpenForm("编辑", urls);

            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("添加 ", "{:url('add')}");
                return false;
            } else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "del") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
